//package com.yanftch.jsonformat.json2ets.generator
//
//import com.intellij.ide.projectView.ProjectView
//import com.intellij.openapi.actionSystem.AnActionEvent
//import com.intellij.openapi.actionSystem.LangDataKeys
//import com.intellij.openapi.progress.ProgressIndicator
//import com.intellij.openapi.progress.ProgressManager
//import com.intellij.openapi.progress.Task
//import com.yanftch.jsonformat.json2ets.exceptions.FileIOException
//import com.yanftch.jsonformat.json2ets.parser.typescript.ParseType
//import kotlinx.coroutines.runBlocking
//import java.io.IOException
//
//class GeneratorDelegate(private val messageDelegate: MessageDelegate = MessageDelegate()) {
//    @Suppress("TooGenericExceptionCaught")
//    fun runGeneration(event: AnActionEvent, json: String, rootName: String = "RootObject", parseType: ParseType, generateSetGet: Boolean = false) {
//        ProgressManager.getInstance().run(
//            object : Task.Backgroundable(
//                event.project, "ets code is generating....", false
//            ) {
//                override fun run(indicator: ProgressIndicator) = runBlocking<Unit> {
//                    try {
//                        val generator = TsGenerator()
//                        generator.generateFromJsonByDocument(json, event, rootName, parseType, generateSetGet)
//                        messageDelegate.showMessage("ets interface has been generated", event)
//                    } catch (e: Exception) {
//                        when (e) {
//                            is IOException -> messageDelegate.catchException(FileIOException(), event)
//                            else -> messageDelegate.catchException(e, event)
//                        }
//                    } finally {
//                        indicator.stop()
//                        event.project?.let { ProjectView.getInstance(it).refresh() }
//                        event.getData(LangDataKeys.VIRTUAL_FILE)?.refresh(false, true)
//                    }
//                }
//            }
//        )
//    }
//    @Suppress("TooGenericExceptionCaught")
//    fun runGenerationToFile(event: AnActionEvent, json: String, rootName: String = "RootObject", parseType: ParseType) {
//        ProgressManager.getInstance().run(
//            object : Task.Backgroundable(
//                event.project, "ets code is generating....", false
//            ) {
//                override fun run(indicator: ProgressIndicator) = runBlocking<Unit> {
//                    try {
//                        val generator = TsGenerator()
//                        generator.generateTsFile(json, event, rootName, parseType)
//                        messageDelegate.showMessage("ets interface has been generated", event)
//                    } catch (e: Throwable) {
//                        when (e) {
//                            is IOException -> messageDelegate.catchException(FileIOException(), event)
//                            else -> messageDelegate.catchException(e, event)
//                        }
//                    } finally {
//                        indicator.stop()
//                        event.project?.let { ProjectView.getInstance(it).refresh() }
//                        event.getData(LangDataKeys.VIRTUAL_FILE)?.refresh(false, true)
//                    }
//                }
//            }
//        )
//    }
//}
